package com.gy.mbaselibrary.services;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
/**
 * 创建者：高业
 * 邮箱：15234150168@163.com
 * 时间：2018/2/6
 * 描述：
 * 修改人：
 * 修改时间：2018/2/6
 * 修改备注：
 */
public class KillSelfService extends Service {
    /**关闭应用后多久重新启动*/
    private static  long stopDelayed=2000;
    private Handler handler;
    private String PackageName;
    public KillSelfService() {
        handler = new Handler();
    }

    @Override
    public int onStartCommand(final Intent intent, int flags, int startId) {
        stopDelayed=intent.getLongExtra("Delayed",2000);
        PackageName=intent.getStringExtra("PackageName");
        handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(PackageName);
                                    startActivity(LaunchIntent);
                                    KillSelfService.this.stopSelf();
                                }
                            },stopDelayed);
        return super.onStartCommand(intent, flags, startId);
    }


    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

}
